import myAxios from "../plugins/myAxios";
import { Toast } from "vant";
import { toDate } from "../util/dateTimeFormat"
// 创建用户
export const createTeam = async (param) => {
    let code = 0;
    param.expireTime = toDate(new Date(Date.parse(param.expireTime)))
    await myAxios.post("/team", {
        ...param
    }).then((res) => {
        if (res.data.code == 1) {
            code = 1;
            Toast.success("队伍创建成功");
            console.log("队伍创建成功");
        } else {
            Toast.fail("队伍创建失败：" + res.data.msg);
            console.error("队伍创建失败：" + res.data.msg);
        }
    });
    return code;
};
// 修改用户
export const updateTeam = async (param) => {
    let code = 0;
    param.expireTime = toDate(new Date(Date.parse(param.expireTime)))
    await myAxios.put("/team", {
        ...param
    }).then((res) => {
        if (res.data.code == 1) {
            code = 1;
            Toast.success("队伍修改成功");
            console.log("队伍修改成功");
        } else {
            Toast.fail("队伍修改失败：" + res.data.msg);
            console.error("队伍修改失败：" + res.data.msg);
        }
    });
    return code;
};
// 加入队伍
export const joinTeam = async (teamId, password) => {
    let code = 0;
    await myAxios.post("/team/join", {
        teamId: teamId,
        password: password
    }).then((res) => {
        if (res.data.code == 1) {
            code = 1;
            Toast.success("加入队伍成功");
            console.log("加入队伍成功");
        } else {
            Toast.fail("加入队伍失败：" + res.data.msg);
            console.error("加入队伍失败：" + res.data.msg);
        }
    });
    return code;
};
// 用户退出队伍
export const exitTeam = async (teamId) => {
    let code = 0;
    await myAxios.post(`/team/quit/${teamId}`).then((res) => {
        if (res.data.code == 1) {
            code = 1;
            Toast.success("加入队伍成功");
            console.log("加入队伍成功");
        } else {
            Toast.fail("加入队伍失败：" + res.data.msg);
            console.error("加入队伍失败：" + res.data.msg);
        }
    });
    return code;
};
// 队长解散队伍
export const disbandTeam = async (teamId) => {
    let code = 0;
    await myAxios.delete(`/team/${teamId}`).then((res) => {
        if (res.data.code == 1) {
            code = 1;
            Toast.success("解散队伍成功");
            console.log("解散队伍成功");
        } else {
            Toast.fail("解散队伍失败：" + res.data.msg);
            console.error("解散队伍失败：" + res.data.msg);
        }
    });
    return code;
};